-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add get mappings support to high-level rest client #30889
Conversation
This adds support for the get mappings API to the high level rest client. Relates to elastic#27205
Pinging @elastic/es-core-infra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few minor comments, LGTM otherwise
"_mapping", getMappingsRequest.types())); | ||
|
||
Params parameters = new Params(request); | ||
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this being set in the corresponding REST action, would you mind opening another PR to fix that? It needs to be added to the SPEC too.
|
||
Params parameters = new Params(request); | ||
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); | ||
parameters.withIndicesOptions(getMappingsRequest.indicesOptions()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we need to set the local flag also
@@ -191,6 +192,16 @@ static Request putMapping(PutMappingRequest putMappingRequest) throws IOExceptio | |||
return request; | |||
} | |||
|
|||
static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOException { | |||
Request request = new Request(HttpGet.METHOD_NAME, endpoint(getMappingsRequest.indices(), | |||
"_mapping", getMappingsRequest.types())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you need to protect both indices and types from NPEs. Unfortunately you can set null from their setter methods. We already do this for other API.
getMappingRequest.indices(indices); | ||
|
||
String type = randomAlphaOfLengthBetween(3, 10); | ||
getMappingRequest.types(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test setting indices and/or types null also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also test with no types provided?
Map<String, String> expectedParams = new HashMap<>(); | ||
|
||
setRandomIndicesOptions(getMappingRequest::indicesOptions, getMappingRequest::indicesOptions, expectedParams); | ||
setRandomMasterTimeout(getMappingRequest, expectedParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a test around the local flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, was added
return this.mappings.equals(other.mappings); | ||
} | ||
|
||
private static final class Fields { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get rid of this inner class and declare the field at the top-level?
@@ -83,6 +84,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC | |||
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(); | |||
getMappingsRequest.indices(indices).types(types); | |||
getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions())); | |||
getMappingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thanks I hadn't noticed that you already added this missing line ++ can you double check the spec too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it to the spec
message = String.format(Locale.ROOT, "types [%s] missing", toNamesString(difference.toArray(new String[0]))); | ||
} | ||
final String message = String.format(Locale.ROOT, "type" + (difference.size() == 1 ? "" : "s") + | ||
" [%s] missing", Strings.collectionToCommaDelimitedString(difference)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the toNamesString method if we no longer use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -129,47 +131,15 @@ public RestResponse buildResponse(final GetMappingsResponse response, final XCon | |||
status = RestStatus.OK; | |||
} else { | |||
status = RestStatus.NOT_FOUND; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do think about moving all this logic to the corresponding transport action (as a follow-up)? I didn't look too close but I think that this causes different behaviour between REST and transport at the moment, it would be nice to have a simpler REST action maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't love this logic but this isn't the place to remove it, I think it'd be fine as a follow-up. The difficulty is that we are not consistent here (see: #30768 (comment) ) I think we need to sort that out before removing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not talking about removing this (I agree it's not nice and we should talk about that), but rather moving this logic to the transport action. That would maintain the same behaviour at REST and most likely change it for transport client users. Anyway, doesn't belong here.
@@ -83,6 +84,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC | |||
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may also want to look at removing RestGetAllMappingsAction if possible. As a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, definitely +1 on removing that if possible.
Thanks for taking a look @javanna, I think I've addressed all of your comments |
-------------------------------------------------- | ||
<1> Returning all indices' mappings | ||
<2> Retrieving the mappings for a particular index and type | ||
<3> Getting the mappings for the "tweet" as a Java Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get these errors when building the docs:
asciidoc: WARNING: get_mappings.asciidoc: line 14: list item index: expected 2 got 1
asciidoc: WARNING: get_mappings.asciidoc: line 15: list item index: expected 3 got 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why these occur, I checked and there are 3 annotations in IndicesClientDocumentationIT for this tag, and 3 here, not sure why they are off-by-one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM besides the docs issue, feel free to merge once those are addressed. thanks @dakrone !
Thanks for taking a look @javanna |
@dakrone do you plan on backporting this as well? |
This adds support for the get mappings API to the high level rest client. Relates to #27205
* elastic/6.x: [Rollup] Disallow index patterns that match the rollup index (#30491) Revert "Fixing MixedClusterClientYamlTestSuiteIT" Fixing MixedClusterClientYamlTestSuiteIT Add get mappings support to high-level rest client (#30889) [DOCS] Fixes security example (#31082) Allow terms query in _rollup_search (#30973)
@@ -95,6 +95,7 @@ include::indices/clear_cache.asciidoc[] | |||
include::indices/force_merge.asciidoc[] | |||
include::indices/rollover.asciidoc[] | |||
include::indices/put_mapping.asciidoc[] | |||
include::indices/get_mappings.asciidoc[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heya @dakrone this is not enough for the page to be linked, in fact this API is currently missing in our docs, would you mind fixing that please?
This commit adds the high-level rest client docs for the get mappings API that was added in elastic#30889
This commit adds the high-level rest client docs for the get mappings API that was added in #30889
This commit adds the high-level rest client docs for the get mappings API that was added in #30889
This adds support for the get mappings API to the high level rest client.
Relates to #27205